/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IJFCliente.java
 *
 * Created on 18/06/2011, 10:34:49
 */
package br.unesp.demac.bcc.soo.view.cadastro;

import br.unesp.demac.bcc.soo.bean.Contato;
import br.unesp.demac.bcc.soo.bean.Endereco;
import br.unesp.demac.bcc.soo.bean.Login;
import br.unesp.demac.bcc.soo.bean.Pessoa;
import br.unesp.demac.bcc.soo.dao.PessoaDAO;
import br.unesp.demac.bcc.soo.dao.PessoaDAOImp;
import br.unesp.demac.bcc.soo.util.Dialog;
import java.util.ArrayList;

/**
 *
 * @author flavioam
 */
public final class JIFCliente extends javax.swing.JInternalFrame {

    /** Creates new form IJFCliente */
    public JIFCliente() {
        initComponents();

        btnCadCancel.setEnabled(false);
        btnEditCancela.setEnabled(false);
        btnEditSalvaCliente.setEnabled(false);
        btnCadSalvaCliente.setEnabled(false);
        habilitaCampos(false, true);
        habilitaCampos(false, false);
        populaClientes();
        preencheCamposEditar();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtCadNome = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtCadCpf = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtCadNomeUsuario = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtCadSenha = new javax.swing.JPasswordField();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtCadEmail = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtCadTelResid = new javax.swing.JTextField();
        txtCadTelDel = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtCadTelCom = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        txtCadEnd = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtCadCidade = new javax.swing.JTextField();
        txtCadEstado = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        btnCadAdCliente = new javax.swing.JButton();
        btnCadSalvaCliente = new javax.swing.JButton();
        btnCadCancel = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        txtEditNomeUsuario = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtEditSenha = new javax.swing.JPasswordField();
        jPanel8 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        txtEditEnd = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtEditCidade = new javax.swing.JTextField();
        txtEditEstado = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        txtEditEmail = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        txtEditTelResid = new javax.swing.JTextField();
        txtEditTelCel = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtEditTelCom = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        btnEditSalvaCliente = new javax.swing.JButton();
        btnEditDeletaCliente = new javax.swing.JButton();
        btnEditCancela = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        txtEditCpf = new javax.swing.JTextField();
        comboEditNome = new javax.swing.JComboBox();
        btnEditEditar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Cadastro de Clientes");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico16x16/customer.png"))); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Cliente"));
        jPanel3.setName(""); // NOI18N

        jLabel1.setText("Nome: ");

        jLabel2.setText("Cpf: ");

        txtCadCpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCadCpfActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCadNome, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(txtCadCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(59, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtCadNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtCadCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Login"));
        jPanel4.setName(""); // NOI18N

        jLabel3.setText("Nome de Usuário: ");

        jLabel4.setText("Senha: ");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCadNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCadSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(87, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtCadNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtCadSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Contato"));
        jPanel5.setName(""); // NOI18N

        jLabel5.setText("E-mail: ");

        txtCadEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCadEmailActionPerformed(evt);
            }
        });

        jLabel6.setText("Telefone Resid.: ");

        jLabel7.setText("Telefone Cel.: ");

        jLabel8.setText("Telefone Com.: ");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtCadEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(txtCadTelDel, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtCadTelResid, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtCadTelCom, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(90, 90, 90)))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(txtCadEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCadTelResid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtCadTelDel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(txtCadTelCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));
        jPanel6.setName(""); // NOI18N

        jLabel9.setText("Endereço: ");

        txtCadEnd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCadEndActionPerformed(evt);
            }
        });

        jLabel10.setText("Cidade: ");

        jLabel11.setText("Estado");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10))
                .addGap(10, 10, 10)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtCadEnd, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtCadEstado, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtCadCidade, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)))
                .addContainerGap(106, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(txtCadEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCadCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(txtCadEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel9))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        btnCadAdCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/insertUser.png"))); // NOI18N
        btnCadAdCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadAdClienteActionPerformed(evt);
            }
        });

        btnCadSalvaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/save.png"))); // NOI18N
        btnCadSalvaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadSalvaClienteActionPerformed(evt);
            }
        });

        btnCadCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/cancel.png"))); // NOI18N
        btnCadCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(9, 9, 9))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnCadAdCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCadSalvaCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCadCancel)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnCadAdCliente)
                    .addComponent(btnCadSalvaCliente)
                    .addComponent(btnCadCancel))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Cadastrar", jPanel1);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Login"));
        jPanel7.setName(""); // NOI18N

        jLabel12.setText("Nome de Usuário: ");

        jLabel13.setText("Senha: ");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEditNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEditSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(87, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtEditNomeUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtEditSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));
        jPanel8.setName(""); // NOI18N

        jLabel14.setText("Endereço: ");

        txtEditEnd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEditEndActionPerformed(evt);
            }
        });

        jLabel15.setText("Cidade: ");

        jLabel16.setText("Estado");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addComponent(jLabel16)
                    .addComponent(jLabel15))
                .addGap(10, 10, 10)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtEditEnd, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtEditEstado, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtEditCidade, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)))
                .addContainerGap(106, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(txtEditEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEditCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(txtEditEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel14))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder("Contato"));
        jPanel9.setName(""); // NOI18N

        jLabel17.setText("E-mail: ");

        txtEditEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEditEmailActionPerformed(evt);
            }
        });

        jLabel18.setText("Telefone Resid.: ");

        jLabel19.setText("Telefone Cel.: ");

        jLabel20.setText("Telefone Com.: ");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel17)
                            .addComponent(jLabel19)
                            .addComponent(jLabel18))
                        .addGap(10, 10, 10)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtEditEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(txtEditTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtEditTelResid, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEditTelCom, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(90, 90, 90)))
                .addContainerGap(82, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(txtEditEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEditTelResid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(txtEditTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel20)
                            .addComponent(txtEditTelCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel17))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnEditSalvaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/save.png"))); // NOI18N
        btnEditSalvaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditSalvaClienteActionPerformed(evt);
            }
        });

        btnEditDeletaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/deleteUser.png"))); // NOI18N
        btnEditDeletaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditDeletaClienteActionPerformed(evt);
            }
        });

        btnEditCancela.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/cancel.png"))); // NOI18N
        btnEditCancela.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditCancelaActionPerformed(evt);
            }
        });

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Cliente"));
        jPanel10.setName(""); // NOI18N

        jLabel21.setText("Nome: ");

        jLabel22.setText("Cpf: ");

        txtEditCpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEditCpfActionPerformed(evt);
            }
        });

        comboEditNome.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboEditNomeItemStateChanged(evt);
            }
        });
        comboEditNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboEditNomeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboEditNome, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addGap(18, 18, 18)
                        .addComponent(txtEditCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(comboEditNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(txtEditCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        btnEditEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/unesp/demac/bcc/soo/img/ico48x48/editUser.png"))); // NOI18N
        btnEditEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditEditarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(9, 9, 9))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(btnEditEditar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditSalvaCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditDeletaCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnEditCancela)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEditSalvaCliente)
                    .addComponent(btnEditDeletaCliente)
                    .addComponent(btnEditCancela)
                    .addComponent(btnEditEditar))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Editar", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 875, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 395, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(69, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtCadCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCadCpfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCadCpfActionPerformed

    private void txtCadEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCadEmailActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtCadEmailActionPerformed

    private void txtCadEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCadEndActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCadEndActionPerformed

    private void txtEditEndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEditEndActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEditEndActionPerformed

    private void txtEditEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEditEmailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEditEmailActionPerformed

    private void txtEditCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEditCpfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEditCpfActionPerformed

    private void btnCadAdClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadAdClienteActionPerformed
        // TODO add your handling code here:
        habilitaCampos(true, true);
        txtCadNome.requestFocus();
        btnCadCancel.setEnabled(true);
        btnCadSalvaCliente.setEnabled(true);
        btnCadAdCliente.setEnabled(false);
    }//GEN-LAST:event_btnCadAdClienteActionPerformed

    private void btnCadCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadCancelActionPerformed
        // TODO add your handling code here:
        limpaCampos(true);
        habilitaCampos(false, true);
        btnCadCancel.setEnabled(false);
        btnCadSalvaCliente.setEnabled(false);
        btnCadAdCliente.setEnabled(true);
    }//GEN-LAST:event_btnCadCancelActionPerformed

    private void btnCadSalvaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadSalvaClienteActionPerformed
        // TODO add your handling code here:

        btnCadAdCliente.setEnabled(false);
        btnCadCancel.setEnabled(false);
        btnCadSalvaCliente.setEnabled(false);

        try {

            Login l = new Login();
            Endereco end = new Endereco();
            Contato c = new Contato();
            Pessoa p = new Pessoa();

            p.setNome(txtCadNome.getText());
            p.setCpf(txtCadCpf.getText());

            c.setEmail(txtCadEmail.getText());
            c.setTelefoneCelular(txtCadTelDel.getText());
            c.setTelefoneComercial(txtCadTelCom.getText());
            c.setTelefoneResidencial(txtCadTelResid.getText());

            end.setCidade(txtCadCidade.getText());
            end.setEndereco(txtCadEnd.getText());
            end.setEstado(txtCadEstado.getText());

            l.setSenha(String.valueOf(txtCadSenha.getPassword(), 0, txtCadSenha.getPassword().length));
            l.setUsuario(txtCadNomeUsuario.getText());

            p.setContato(c);
            p.setLogin(l);
            p.setEndereco(end);

            PessoaDAO pDao = new PessoaDAOImp();

            pDao.salvaPessoa(p);

            limpaCampos(true);
            habilitaCampos(false, true);
            btnCadSalvaCliente.setEnabled(false);
            btnCadAdCliente.setEnabled(true);

            comboEditNome.addItem(p);

            Dialog.sucessoDialog("Cliente cadastrado com sucesso!");



        } catch (Exception e) {
            btnCadSalvaCliente.setEnabled(true);
            btnCadCancel.setEnabled(true);
            Dialog.errorDialog(e.getMessage());
        }


    }//GEN-LAST:event_btnCadSalvaClienteActionPerformed

    private void comboEditNomeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboEditNomeItemStateChanged
        // TODO add your handling code here:
        preencheCamposEditar();

    }//GEN-LAST:event_comboEditNomeItemStateChanged

    private void btnEditEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditEditarActionPerformed
        // TODO add your handling code here:
        btnEditEditar.setEnabled(false);
        btnEditCancela.setEnabled(true);
        btnEditSalvaCliente.setEnabled(true);
        btnEditDeletaCliente.setEnabled(false);
        habilitaCampos(true, false);
    }//GEN-LAST:event_btnEditEditarActionPerformed

    private void btnEditCancelaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditCancelaActionPerformed
        // TODO add your handling code here:
        btnEditCancela.setEnabled(false);
        btnEditDeletaCliente.setEnabled(true);
        btnEditEditar.setEnabled(true);
        btnEditSalvaCliente.setEnabled(false);
        habilitaCampos(false, false);
    }//GEN-LAST:event_btnEditCancelaActionPerformed

    private void btnEditDeletaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditDeletaClienteActionPerformed
        // TODO add your handling code here:        

        try {

            btnEditCancela.setEnabled(false);
            btnEditDeletaCliente.setEnabled(false);
            btnEditEditar.setEnabled(false);
            btnEditSalvaCliente.setEnabled(false);

            PessoaDAO pDao = new PessoaDAOImp();
            Pessoa p = (Pessoa) comboEditNome.getSelectedItem();
            pDao.deletaPessoa(p);

            comboEditNome.removeItem(p);

            habilitaCampos(false, false);
            btnEditCancela.setEnabled(false);
            btnEditDeletaCliente.setEnabled(true);
            btnEditEditar.setEnabled(true);
            btnEditSalvaCliente.setEnabled(false);

            Dialog.sucessoDialog("Usuário Deletado com Sucesso!");

        } catch (Exception e) {

            Dialog.errorDialog(e.getMessage());
        }

    }//GEN-LAST:event_btnEditDeletaClienteActionPerformed

    private void comboEditNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboEditNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboEditNomeActionPerformed

    private void btnEditSalvaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditSalvaClienteActionPerformed
        // TODO add your handling code here:

        try {

            btnEditCancela.setEnabled(false);
            btnEditDeletaCliente.setEnabled(false);
            btnEditEditar.setEnabled(false);
            btnEditSalvaCliente.setEnabled(false);

            Login l = new Login();
            Endereco end = new Endereco();
            Contato c = new Contato();
            Pessoa p = (Pessoa) comboEditNome.getSelectedItem();

            p.setCpf(txtEditCpf.getText());

            c.setEmail(txtEditEmail.getText());
            c.setTelefoneCelular(txtEditTelCel.getText());
            c.setTelefoneComercial(txtEditTelCom.getText());
            c.setTelefoneResidencial(txtEditTelResid.getText());

            end.setCidade(txtEditCidade.getText());
            end.setEndereco(txtEditEnd.getText());
            end.setEstado(txtEditEstado.getText());

            l.setSenha(String.valueOf(txtEditSenha.getPassword(), 0, txtEditSenha.getPassword().length));
            l.setUsuario(txtEditNomeUsuario.getText());

            p.setContato(c);
            p.setLogin(l);
            p.setEndereco(end);

            PessoaDAO pDao = new PessoaDAOImp();

            if (pDao.editaPessoa(p)) {

                comboEditNome.removeItem(p);
                comboEditNome.addItem(p);

                Dialog.sucessoDialog("Cliente Atualizado com Sucesso!");
            } else {
                Dialog.errorDialog("Erro ao atualizar cliente.");
            }


        } catch (Exception e) {

            Dialog.errorDialog(e.getMessage());
        }

        habilitaCampos(false, false);
        btnEditCancela.setEnabled(false);
        btnEditDeletaCliente.setEnabled(true);
        btnEditEditar.setEnabled(true);
        btnEditSalvaCliente.setEnabled(false);

    }//GEN-LAST:event_btnEditSalvaClienteActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCadAdCliente;
    private javax.swing.JButton btnCadCancel;
    private javax.swing.JButton btnCadSalvaCliente;
    private javax.swing.JButton btnEditCancela;
    private javax.swing.JButton btnEditDeletaCliente;
    private javax.swing.JButton btnEditEditar;
    private javax.swing.JButton btnEditSalvaCliente;
    private javax.swing.JComboBox comboEditNome;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField txtCadCidade;
    private javax.swing.JTextField txtCadCpf;
    private javax.swing.JTextField txtCadEmail;
    private javax.swing.JTextField txtCadEnd;
    private javax.swing.JTextField txtCadEstado;
    private javax.swing.JTextField txtCadNome;
    private javax.swing.JTextField txtCadNomeUsuario;
    private javax.swing.JPasswordField txtCadSenha;
    private javax.swing.JTextField txtCadTelCom;
    private javax.swing.JTextField txtCadTelDel;
    private javax.swing.JTextField txtCadTelResid;
    private javax.swing.JTextField txtEditCidade;
    private javax.swing.JTextField txtEditCpf;
    private javax.swing.JTextField txtEditEmail;
    private javax.swing.JTextField txtEditEnd;
    private javax.swing.JTextField txtEditEstado;
    private javax.swing.JTextField txtEditNomeUsuario;
    private javax.swing.JPasswordField txtEditSenha;
    private javax.swing.JTextField txtEditTelCel;
    private javax.swing.JTextField txtEditTelCom;
    private javax.swing.JTextField txtEditTelResid;
    // End of variables declaration//GEN-END:variables

    public void habilitaCampos(boolean habilitar, boolean cadastro) {

        if (cadastro) {

            txtCadCidade.setEnabled(habilitar);
            txtCadCpf.setEnabled(habilitar);
            txtCadEmail.setEnabled(habilitar);
            txtCadEnd.setEnabled(habilitar);
            txtCadEstado.setEnabled(habilitar);
            txtCadNome.setEnabled(habilitar);
            txtCadNomeUsuario.setEnabled(habilitar);
            txtCadSenha.setEnabled(habilitar);
            txtCadTelCom.setEnabled(habilitar);
            txtCadTelDel.setEnabled(habilitar);
            txtCadTelResid.setEnabled(habilitar);

        } else {

            txtEditCidade.setEnabled(habilitar);
            txtEditCpf.setEnabled(habilitar);
            txtEditEmail.setEnabled(habilitar);
            txtEditEnd.setEnabled(habilitar);
            txtEditEstado.setEnabled(habilitar);
            txtEditNomeUsuario.setEnabled(habilitar);
            txtEditSenha.setEnabled(habilitar);
            txtEditTelCel.setEnabled(habilitar);
            txtEditTelCom.setEnabled(habilitar);
            txtEditTelResid.setEnabled(habilitar);
        }
    }

    public void limpaCampos(boolean cadastro) {

        if (cadastro) {

            txtCadCidade.setText("");
            txtCadCpf.setText("");
            txtCadEmail.setText("");
            txtCadEnd.setText("");
            txtCadEstado.setText("");
            txtCadNome.setText("");
            txtCadNomeUsuario.setText("");
            txtCadSenha.setText("");
            txtCadTelCom.setText("");
            txtCadTelDel.setText("");
            txtCadTelResid.setText("");

        } else {

            txtEditCidade.setText("");
            txtEditCpf.setText("");
            txtEditEmail.setText("");
            txtEditEnd.setText("");
            txtEditEstado.setText("");
            txtEditNomeUsuario.setText("");
            txtEditSenha.setText("");
            txtEditTelCel.setText("");
            txtEditTelCom.setText("");
            txtEditTelResid.setText("");
        }

    }

    public void populaClientes() {
        try {
            PessoaDAO pDao = new PessoaDAOImp();

            ArrayList<Pessoa> l;

            l = pDao.selecionaTodosClientes();


            for (Pessoa p : l) {

                comboEditNome.addItem(p);
            }
        } catch (Exception ex) {
            Dialog.errorDialog(ex.getMessage());
        }
    }

    public void preencheCamposEditar() {

        Pessoa p = (Pessoa) comboEditNome.getSelectedItem();

        if (p != null) {

            txtEditCidade.setText(p.getEndereco().getCidade());
            txtEditCpf.setText(p.getCpf());
            txtEditEmail.setText(p.getContato().getEmail());
            txtEditEnd.setText(p.getEndereco().getEndereco());
            txtEditEstado.setText(p.getEndereco().getEstado());
            txtEditNomeUsuario.setText(p.getLogin().getUsuario());
            txtEditSenha.setText(p.getLogin().getSenha());
            txtEditTelCel.setText(p.getContato().getTelefoneCelular());
            txtEditTelCom.setText(p.getContato().getTelefoneComercial());
            txtEditTelResid.setText(p.getContato().getTelefoneResidencial());
        }
    }
}
